//
//  HJChatMessageImageCell.m
//  XWC
//
//  Created by Hello on 2022/10/25.
//

#import "HJChatMessageImageCell.h"
#import "HJChatMessageImageLayout.h"
#import "HJChatMessageModel.h"

@interface HJChatMessageImageCell()

@property (nonatomic, weak) UIView *markContentView;

@end


@implementation HJChatMessageImageCell

 
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
      
        UIImageView *imageView = [UIImageView addToView:self.bubbleView];
        imageView.contentMode = UIViewContentModeScaleAspectFill;
        _contentImageView = imageView;
    }
    return self;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    _contentImageView.frame = CGRectMake(0, 0, self.messageLayout.containerViewRect.size.width, self.messageLayout.containerViewRect.size.height);

}

- (void)setMessageLayout:(HJChatMessageLayout *)messageLayout {
    [super setMessageLayout:messageLayout];
    
    if (TJIM_isSelf(messageLayout.messageModel.senderId)) {
        
        if ([[NSFileManager defaultManager] fileExistsAtPath:messageLayout.messageModel.thumbnailPath]) {
            _contentImageView.image = [UIImage imageWithContentsOfFile:messageLayout.messageModel.thumbnailPath];
        } else {
            _contentImageView.image = [UIImage imageNamed:loadImageDefaultImageName];
        }
    } else {
        if (isEmptyString(messageLayout.messageModel.thumbnailUrl)) {
            _contentImageView.image = [UIImage imageNamed:loadImageDefaultImageName];
        } else {
            [_contentImageView tj_setImageWithUrl:messageLayout.messageModel.thumbnailUrl placeholderImage:[UIImage imageNamed:loadImageDefaultImageName]];
        }
    }
}
 
@end
